const fs = require('fs')
function staticFile(extStr,req,res) {
    if(extStr === 'css'){
        //正常输出css文件流
        //content-type text/plain  text/html  text/css  text/js  image/jpg  image/png  image/gif
        res.writeHead(200,{'Content-Type':'text/css'})  //http的响应头
        fs.createReadStream(global.rootPath+req.url,'utf8').pipe(res)
        return true
    }else if(extStr === 'js'){
        res.writeHead(200,{'Content-Type':'text/js'})
        fs.createReadStream(global.rootPath+req.url,'utf8').pipe(res)
        return true
    }else if(['jpg','png','gif','jpeg'].includes(extStr)){
        res.writeHead(200,{'Content-Type':'image/'+extStr})
        fs.createReadStream(global.rootPath+req.url).pipe(res)
        return true
    }

}

module.exports = staticFile